package guoanmaker.operator.business.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.InRoundPhone;

import guoanmaker.operator.business.model.OperatorHotServerPc;
import guoanmaker.operator.business.service.OperatorHotServerPcServiceIntegerface;

import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;
/**
 * 保存pc端热门服务
* @ClassName: OperatorHotServerPcController
* @Description:TODO (这里用一句话描述这个类的作用) 
* @author lihongyu
* @date 2017年12月19日 下午8:46:22 
*  
 */
@RestController
@RequestMapping(ApiController.OPERATOR_HOT_SERVER_PC)
public class OperatorHotServerPcController {
	@Autowired
    private  OperatorHotServerPcServiceIntegerface operatorHotServerPcServiceIntegerface;
	
	 /** 
	    * @Title: saveHotServer
	    * @Description: 新增/修改热门服务 
	    * @param: OperatorHotServer   
	    * @return AjaxJson    
	    * @throws 
	    */
	    @ApiOperation(value = "保存pc热门服务", notes = "新增/修改pc热门服务")
	    @PostMapping(value = "saveHotServer")
	    public AjaxJson saveHotServer(@RequestBody InRoundPhone inRoundPhone) {
	    	AjaxJson ajaxJson=new AjaxJson();
	    	try{
	    		OperatorHotServerPc[] OperatorHotServerPcs=inRoundPhone.getOperatorHotServerPcs();
	    	
	    	operatorHotServerPcServiceIntegerface.delectAllBycitycode(inRoundPhone.getCityId());
	    	for(OperatorHotServerPc hotserver:OperatorHotServerPcs){
	    		/*if(null!=hotserver.getId()&&!hotserver.getId().equals("")){
	    			operatorHotServerServiceInterface.deleteHotServerById(hotserver.getId());
	    		}*/
	    		hotserver.setCityId(inRoundPhone.getCityId());
	    		hotserver.setCreateDate(new Date());
	    		operatorHotServerPcServiceIntegerface.saveHotServer(hotserver);
	    	}
	    	ajaxJson.setSuccess(true).setStatus(200).setData(null);
	    	}catch(Exception e){
	    		e.printStackTrace();
	    		ajaxJson.setSuccess(false).setStatus(250).setData(null);
	    	}
	        return ajaxJson;
	    }

	    /** 
	     * @Title: deleteHotServerById
	     * @Description: 根据Id删除热门服务
	     * @param: String id  
	     * @return AjaxJson 
	     * @throws 
	     */
	    @ApiOperation(value = "删除pc热门服务", notes = "根据Id删除pc热门服务")
	    @DeleteMapping(value = "deleteHotServerPc")
	    public AjaxJson deleteHotServerById(String id) {
	    	AjaxJson ajaxJson=new AjaxJson();
	    	operatorHotServerPcServiceIntegerface.deleteHotServerById(id);
	        return ajaxJson.setSuccess(true).setStatus(200).setData("数据删除成功!");
	    }
	    
	    @ApiOperation(value = "根据code查询所有PC热门服务", notes = "根据code查询所有PC热门服务")
	    @PostMapping(value = "getAllHotServerPcByCityId")
	    public AjaxJson getAllHotServerPcByCityId(String cityId) {
	    	AjaxJson ajaxJson=new AjaxJson();
	    	try{
	    	List<OperatorHotServerPc> hotservers=operatorHotServerPcServiceIntegerface.getAllAndServerName(cityId);
	    	
	    		ajaxJson.setSuccess(true).setStatus(200).setData(hotservers);
	    	}catch(Exception e){
	    		e.printStackTrace();
	    		ajaxJson.setSuccess(true).setStatus(250).setData(null);
	    		
	    	}
	        return ajaxJson;
	    }
}
